<?php
include_once("../configure/admin.config.inc.php");	//--> admin global var
include_once("db.inc.php");							//--> db global var
include_once("Smarty.class.php");					//--> out template
include_once("Operation.php");						//--> Operation
include_once("Merchant.php");						//--> Merchant
require_once("controlHeader.php");					//--> system control header

$objOperate 	= new Operation($objSession->getLanguage());	//--> Operation
$objMerchant 	= new Merchant(DB_TAG_SYSTEM, $uid);			//--> Merchant

$error_message = '';

$arrOperate = $objOperate->arrGetFromGroupIDAndMenuID($gid, $menuid);
if(count($arrOperate) > 0){
	$strQuery = $_SERVER["REQUEST_URI"];
	$arrUrlInfo 	= pathinfo($strQuery);
	$selfFileName	= $arrUrlInfo['filename'];
	
	$arrOperateAllInfo = $objOperate->listFromCustom($arrOperate, " WHERE id in (".implode(",", $arrOperate).") AND name != 'Add'");
	
	$i = 0; 
	foreach($arrOperateAllInfo as $key => $value){
		$strFileName = $selfFileName."_".$value['name'].".php";

		if(file_exists($strFileName)){
			$arrOperateInfo[$i]['name'] 		= $value['name'];
			$arrOperateInfo[$i]['viewName'] 	= $value['name'];
			
			$i++;
		}
	}
}

if(isset($_GET['keyword']) && !empty($_GET['keyword'])){
	$keyword 	= $_GET['keyword'];
	$searchType = $_GET['searchType'];
	
	if(empty($keyword)){
		$error_message	= 'The keyword should\'t be empty.';
	}else{
		if($searchType == 'id'){
			if(is_numeric($keyword))
				$where	= " WHERE id = $keyword";
			else
				$error_message	= 'The keyword should\'t be product ID.';
		}else if($searchType == 'name'){
			$where	= " WHERE languageID = $LANGEUAGE_ID AND customers_name like '%$keyword%'";
		}else if($searchType == 'status'){
			$where	= " WHERE languageID = $LANGEUAGE_ID AND status like '%$keyword%'";
		}else{
			$where	= " WHERE languageID = $LANGEUAGE_ID AND customers_name like '%$keyword%'";
		}
	}
}

$where	.= " ORDER BY id DESC";

$arrDataList = $objMerchant->lists($arrOperate, $where, $page, DISPLAY_DATA_SIZE, '');

$arrSearchType = array('id' => 'Number', 'name' => 'Name', 'status' => 'Status');

/*----- out html -----*/
$smarty = new Smarty();					//----- out template
$smarty->template_dir = TEMPLATE_SYS_DIR;
$smarty->compile_dir  = COMPILE_SYS_DIR;

$smarty->assign('error_message', $error_message);
$smarty->assign('menuGid', $menuGid);
$smarty->assign('menuid', $menuid);

$smarty->assign('selfFileName', $selfFileName);
$smarty->assign('arrOperateInfo', $arrOperateInfo);

$smarty->assign('arrDataList', $arrDataList);

$smarty->assign('PAGE_BAR', $objMerchant->pagenav);

$smarty->assign('arrSearchType', $arrSearchType);
$smarty->assign('searchTypeS', $searchType);
$smarty->assign('keyword', $keyword);

$smarty->display('listMerchant.htm');
?>
